package com.example.zhaoyulu.yunzhiapp;

import android.content.Intent;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.example.network.getRetrofitService;
import com.example.network.javaBeans.yzjyinfo;
import com.example.zhaoyulu.yunzhiapp.zylUtils.GlideRoundTransform;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class watchVideoActivity extends zylBaseActivity {

    VideoView watchVideo;

    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {


        @Override
        public void onCompletion(MediaPlayer mp) {
            //Toast.makeText( watchVideoActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_watch_video);

        Intent intent = getIntent();
        //从Intent当中根据key取得value
        if (intent != null) {
            String url = intent.getStringExtra("url");
            String id = intent.getStringExtra("id");
        watchVideo=findViewById(R.id.watchVideo);
        //网络视频
        //设置视频控制器
        watchVideo.setMediaController(new MediaController(this));
        //播放完成回调
        watchVideo.setOnCompletionListener( new MyPlayerOnCompletionListener());
        //设置视频路径
        //videoView.setVideoURI(uri);
        watchVideo.setVideoPath(url);
        //开始播放视频
        watchVideo.start();
        videoLength=watchVideo.getDuration();
        }
        video_img1=findViewById(R.id.video_img1);
        video_img2=findViewById(R.id.video_img2);
        video_img3=findViewById(R.id.video_img3);
        video_img4=findViewById(R.id.video_img4);

        getRetrofitService.getService().getVideoPic("2211").enqueue(new Callback<List<yzjyinfo>>() {
            @Override
            public void onResponse(Call<List<yzjyinfo>> call, Response<List<yzjyinfo>> response) {
                Glide.with(watchVideoActivity.this).load(response.body().get(0).getPic()).centerCrop().transform(new GlideRoundTransform(watchVideoActivity.this)).into(video_img1);
                Glide.with(watchVideoActivity.this).load(response.body().get(1).getPic()).centerCrop().transform(new GlideRoundTransform(watchVideoActivity.this)).into(video_img2);
                Glide.with(watchVideoActivity.this).load(response.body().get(2).getPic()).centerCrop().transform(new GlideRoundTransform(watchVideoActivity.this)).into(video_img3);
                Glide.with(watchVideoActivity.this).load(response.body().get(3).getPic()).centerCrop().transform(new GlideRoundTransform(watchVideoActivity.this)).into(video_img4);
            }

            @Override
            public void onFailure(Call<List<yzjyinfo>> call, Throwable t) {

            }
        });

    }
    private ImageView video_img4;
    private ImageView video_img1;
    private ImageView video_img2;
    private ImageView video_img3;

    public int videoLength=0;
}
